package com.example.ten.service.impl;

import com.aaa.dao.DeptDao;
import com.aaa.entity.Dept;
import com.aaa.service.DeptService;
import com.aaa.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: Jyc
 * @classname: DeptServiceImpl
 * @date: 2023/3/29
 * @time: 14:36
 * @description:
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Resource
    private DeptDao deptDao;


    @Override
    public List<Dept> queryAllDept() {
        //查询状态为1的部门
        Dept dept =new Dept();
        return deptDao.queryByParam(dept);
    }

    @Override
    public PageInfo queryByParam(Page<Dept> page) {
        //使用PageHelper
        //设置分页页码 pageNo 和每页显示数量 pageSize
        PageHelper.startPage(page.getPageNo(),page.getPageSize());
        //执行后端查询，把查询结果封装为PageInfo并返回
        return new PageInfo<Dept>(deptDao.queryByParam(page.getData()));
    }

    @Override
    public Dept queryById(int deptId) {
        //制造空指针异常
        String str = null;
        // System.out.println(str.length());
        //System.out.println(1/0);
        return deptDao.queryById(deptId);
    }

    @Override
    public int add(Dept dept) {
        //添加部门
        int addNum = deptDao.add(dept);
        return addNum;
    }

    @Override
    public int update(Dept dept) {
        int updateNum = deptDao.update(dept);
        return updateNum;
    }

    @Override
    public int deleteById(int deptId) {
        int deleteNum = deptDao.deleteById(deptId);
        return deleteNum;
    }
}
